package com.hk.commons.eunms;

import java.text.MessageFormat;

/**
 * 系统状态码
 */
public enum SysCode implements Enums<String> {
    SUCCESS("000200", "处理成功！"),
    GET_ERROR("999901", "获取数据失败，请刷新重试！"),
    ADD_ERROR("999902", "插入数据失败，请刷新重试！"),
    EDIT_ERROR("999903", "更新数据失败，请刷新重试！"),
    DEL_ERROR("999904", "删除数据失败，请刷新重试！"),
    PARAM_ERROR("999400", "参数有误！【{0}】"),
    NO_AUTH("999401", "无权访问!"),
    UPLOAD_ERROR("999905", "文件上传失败!"),
    REST_AUTH_ERROR("999403", "鉴权失败!"),
    REST_REMOTING_ERROR("999906", "远程调用失败!"),
    USER_NOT_LOGIN("999404", "用户未登录!"),
    SYS_ERROR("999500", "系统开小差了~"),
    LIMITING_ERROR("999600", "访问频繁。稍后再试！");

    private String code;
    private String desc;

    private SysCode(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    @Override
    public String getDesc(Object... objs) {
        return MessageFormat.format(this.desc, objs);
    }

    public boolean equalsCode(String code) {
        return this.code.equals(code);
    }

    //通过value获取对应的枚举对象
    public static SysCode getEnums(String value) {
        for (SysCode code : SysCode.values()) {
            if (code.getCode().equals(value)) {
                return code;
            }
        }
        return null;
    }
}
